{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from genanki import Model, Note, Deck, Package\n",
    "\n",
    "# 1. 定义基础模型\n",
    "BASIC_MODEL = Model(\n",
    "    model_id=1607392319,  # 随机唯一ID\n",
    "    name=\"Basic Model\",\n",
    "    fields=[\n",
    "        {\"name\": \"Front\"},\n",
    "        {\"name\": \"Back\"},\n",
    "    ],\n",
    "    templates=[\n",
    "        {\n",
    "            'name': '卡片1',\n",
    "            'qfmt': '<div class=\"card\">{{正面}}</div>',  # 光标停留在此处触发优化\n",
    "            'afmt': '{{FrontSide}}<hr id=\"answer\">{{背面}}'\n",
    "        }\n",
    "    ]\n",
    "    css=\"\"\"\n",
    "    .card {\n",
    "    font-family: Arial;\n",
    "    font-size: 20px;\n",
    "    text-align: center;\n",
    "    color: #333;\n",
    "    background-color: #f5f5f5;\n",
    "    }\n",
    "    \"\"\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 2. 创建笔记\n",
    "my_note = Note(\n",
    "    model=BASIC_MODEL,\n",
    "    fields=[\n",
    "        \"中国的首都是哪里？\",  # Front字段\n",
    "        \"北京\"               # Back字段\n",
    "    ]\n",
    ")\n",
    "\n",
    "# 3. 创建牌组并添加笔记\n",
    "my_deck = Deck(\n",
    "    deck_id=2059400110,  # 随机唯一ID\n",
    "    name=\"我的基础牌组\"\n",
    ")\n",
    "my_deck.add_note(my_note)\n",
    "\n",
    "# 4. 生成Anki包文件\n",
    "Package(my_deck).write_to_file(\"my_basic_deck.apkg\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
